"""
print("Practice makes perfect!")
"""

"""
num1,num2,num3 = input().split()

print("score1=" + str(num1) + ",score2=" + str(num2) + ",score3=" + str(num3))
"""


"""
brith = int(input())
date = brith % 100
brith //= 100
month = brith % 100
brith //= 100
year = brith
print("year=" + str(year))
if month < 10:
    print("month=" + '0' + str(month))
else:
    print("month=" +  str(month))
if date < 10:
    print("date=" + '0' + str(date))
else:
    print("date=" + str(date))
"""

"""
num = input()
if num >= 140:
    print("Genius")
"""

"""
num1,num2 = input().split()
if num1 == num2 :
    print(str(num1) + '=' + str(num2))
elif num1 > num2 :
    print(str(num1) + '>' + str(num2))
else:
    print(str(num1) + '<' + str(num2))
"""


"""
n1,n2,n3 = input().split()
if n1 > n2 and n1 > n3 :
    print(n1)
elif n2 > n1 and n2 > n3:
    print(n2)
else:
    print(n3)
"""

year,month = input().split()
arr1 = [0,31,28,31,30,31,30,31,31,30,31,30,31]
arr2 = [0,31,29,31,30,31,30,31,31,30,31,30,31]
sum = 0
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 100):
    for i in range (1,month + 1):
        sum += arr2[i]
else:
    for i in range (1,month + 1):
        sum += arr1[i]
print(sum)



